package com.tonicgb.model;

import java.util.Date;

import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.tonicgb.shared.core.crud.entity.BaseEntity;
import com.tonicgb.shared.common.enums.UserType;
import com.tonicgb.shared.core.jwt.contracts.JWTSubject;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;

import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;

@EqualsAndHashCode(callSuper = true)
@Data
@ToString
@TableName("admins")
public class Admins extends BaseEntity<Admins> implements JWTSubject {

    @TableId("id")
    @ApiModelProperty(value = "用户id")
    private Integer id;
    @Min(5)
    @ApiModelProperty(value = "用户名")
    private String name;
    @NotNull(message = "密码不能为空")
    @ApiModelProperty(value = "密码")
    @JsonProperty(access = JsonProperty.Access.WRITE_ONLY)
    private String pwd;
    @ApiModelProperty(value = "用户状态")
    private String status;
    @ApiModelProperty(value = "用户头像")
    private String avatar;
    @ApiModelProperty(value = "创建时间")
    private Date createdAt;
    @JsonFormat(locale = "zh", timezone = "GMT+8", pattern = "yyyy-MM-dd")
    private Date updatedAt;
    @ApiModelProperty(value = "删除时间")
    private Date deletedAt;

    @Override
    public Integer JWTIdentifier() {
        return this.id;
    }

    @Override
    public UserType JWTCustomClaims() {
        return UserType.ADMIN;
    }

}
